package com.ecoolex.chinadutyfree.retailer.job.scheduler;

import java.time.Instant;
import java.util.Calendar;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.ecoolex.chinadutyfree.retailer.core.manager.DirectMailGoodsOrderIncrementDataManager;
import com.ecoolex.chinadutyfree.retailer.core.manager.DirectMailGoodsOrderTotalDataManager;
import com.ecoolex.framework.scheduler.Job;
import com.ecoolex.framework.scheduler.JobComponent;

@JobComponent
public class DirectMailGoodsOrderDataJob{

	private Logger log = LoggerFactory.getLogger(DirectMailGoodsOrderDataJob.class);

	@Autowired
	private DirectMailGoodsOrderTotalDataManager directMailGoodsOrderTotalManager;
	
	@Autowired
	private DirectMailGoodsOrderIncrementDataManager directMailGoodsOrderIncrementManager;


	@Job(name="chinadutyfree.DirectMailGoodsOrderDataJob.orderTotalStatistical",describe = "订单总量统计")
	public void orderTotalStatisticalProcess() {
		try {
			directMailGoodsOrderTotalManager.orderTotalData(this.getClass().getSimpleName());
		} catch (Exception e) {
			log.error("订单总量调度异常", e);
		} finally {
			log.info("调度结束={}", DirectMailGoodsOrderDataJob.class);
		}
	}
	
	/**
	 * 订单增量,每天0点统计昨日数据
	 */
	@Job(name="chinadutyfree.DirectMailGoodsOrderDataJob.orderIncrementStatistical",describe = "订单每日增量统计")
	public void orderIncrementStatisticalProcess() {
		Calendar calendar = Calendar.getInstance();
    	Date now = Date.from(Instant.now());
    	calendar.setTime(now);
    	calendar.add(Calendar.DATE,-1);
    	Date yesterday = calendar.getTime();
		try {
			directMailGoodsOrderIncrementManager.orderIncrementData(this.getClass().getSimpleName(),yesterday,now);
		} catch (Exception e) {
			log.error("订单增量调度异常", e);
		} finally {
			log.info("调度结束={}", DirectMailGoodsOrderDataJob.class);
		}
	}
}
